package com.daohang361.imqq.pugin.encoder;

import com.daohang361.imqq.Asycore.QQUser;
import com.daohang361.imqq.encoder.InterfaceEncoder;
import com.daohang361.imqq.protocol.QQ2011;
import com.daohang361.imqq.tool.ByteArray;
import com.daohang361.imqq.tool.Hex2Bytes;
import com.daohang361.imqq.tool.MyByteSendArray;
import com.daohang361.imqq.tool.MyUtil;

/** 
 * @author naner E-mail:likun3344@163.com 
 * @create time：2011-6-7 下午11:20:52 
 */
public class EncoderAC  implements InterfaceEncoder{
	@Override
	public byte[] encode(QQUser myqq, int c) {
		ByteArray myByte = doHead(myqq, "00AC");
		myByte.putHex("00 00 00 00");
		myByte.putHex("00 38");
		myByte.putByte(myqq.getAttr("token_data_d1"));
		myByte.saveThis();//保存此段作为第0段
		myByte.putHex("03 E8");
		myByte.putHex("7C 33 84 C8");
		myByte.putHex("00 00 05 07");
		myByte.putHex("1F 59 F5 A0 C0 B2 94 85 1F D1 73 25 88 C9 CA 1A");
		myByte.putHex("6A 4B 1C D6 18 7A 03 1A 01 22 3F 0F 2D FE 6C 41");
		myByte.putHex("00 1B");
		myByte.putHex("46 42 46 37 28 4C 44 5F 59 4D 51 56 4B 58 4E 43 ");
		myByte.putHex("4A 52 46 51 30 57 33 2E 6A 70 67");
		myByte.putHex("00 00");
		myByte.saveThis();//保存此段作为第一段
		myByte.teaThis(1, 1,myqq.getAttr("imgKey"));//加密第一段到第一段
		System.out.println("imgKey:"+Hex2Bytes.bytesToHexString(myqq.getAttr("imgKey")));
		doTail(myByte);
		return myByte.getByteList();//返回完整的package
	}
	
	private boolean ignore=false;
	@Override
	public byte[] encode(QQUser myqq, int c,Object...o) {
		System.out.println("使用默认编码器 命令为:"+MyUtil.intTo2Hex(c));
		ByteArray array=doHead(myqq,MyUtil.intTo2Hex(c));
		array.saveThis();//保存此段作为第0段
		array.putByte(myqq.getSend());
		array.saveThis();//保存此段作为第一段
		array.teaThis(1, 1,myqq.getAttr("SessionKey"));//加密第一段到第一段
		array=doTail(array);
		return array.getByteList();
	}

	public ByteArray doHead(QQUser myqq,String HexCommand)
	{
		ByteArray myByte = new MyByteSendArray();
		myByte.putHex("05");//05系列
		myByte.putInt(QQ2011.QQ_PROTOCOL_VERSION);
		myByte.putHex(HexCommand);
		myByte.putHex("00 31");
		myByte.putInt(myqq.getPakage());
		myByte.putInt(myqq.getQq());
		myByte.putHex("01 00 00 00 00 00 00 00");
		return myByte;
	}
	public ByteArray doTail(ByteArray myByte)
	{
		myByte.putInt(QQ2011.QQ_PROTOCOL_PACKAGE_TAIL);
		myByte.saveThis();//保存此段作为第二段
		return myByte;//返回完整的package
	}
	
	@Override
	public boolean getIgnore() {
		
		return ignore;
	}
	
	@Override
	public void setIgnore(boolean ignore) {
		this.ignore=ignore;
	}
	@Override
	public Object invoke(Object... o) {
	return null;
	}
}
